package com.dcm.oss.controller;

import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.common.annotation.IgnoreResponseBodyAdvice;
import com.dcm.oss.service.impl.OssServiceImpl;
import com.dcm.oss.dto.OssCallbackResult;
import com.dcm.oss.dto.OssPolicyResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * [文件上传Oss相关操作接口]
 *
 * @author : [pengrongsheng]
 * @createTime : [2021/3/28]
 */
@RestController
@RequestMapping("/aliyun/oss")
@EnableResponseBodyAdvice
public class OssController {
    @Autowired
    private OssServiceImpl ossService;

    @ApiOperation(value = "单文件上传")
    @RequestMapping(value = "/uploadPic", method = RequestMethod.POST)
    public String uploadPic(MultipartFile multipartFile) {
        return ossService.putPic(multipartFile);
    }

    /**
     * 上传过程中，如果出现网络异常或程序崩溃导致文件上传失败时，将从断点记录处继续上传未上传完成的部分。
     *
     * @param uploadFile
     * @return
     */
    @ApiOperation(value = "断点续传")
    @RequestMapping(value = "checkpointFile", method = RequestMethod.POST)
    public String checkpointFile(MultipartFile uploadFile) {
        return ossService.uploadFile(uploadFile);
    }


}
